package com.cd.university.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cd.university.common.RestResult;
import com.cd.university.controller.form.ProjectTeamForm;
import com.cd.university.service.ProjectTeamService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 陈栋
 * @create 2021/10/15 20:23
 */
@RestController
@RequestMapping("/projectTeam")
public class ProjectTeamController {

    @Autowired
    private ProjectTeamService projectTeamService;

    @PostMapping("/insert")
    @ApiOperation("向项目中插入团队成员")
    public RestResult insertProjectTeamList(@RequestBody JSONObject jsonObject) {
        List<ProjectTeamForm> teamList = jsonObject.getJSONArray("teamList").toJavaList(ProjectTeamForm.class);

        return projectTeamService.insertProjectTeam(teamList);
    }

    @GetMapping("/getUsers")
    @ApiOperation("查询项目的所有的用户")
    public RestResult getUsersByProjectId(@RequestParam("projectId") Integer projectId) {
        return projectTeamService.searchProjectUsers(projectId);
    }


}
